#include <wind_home.h>

#include <widget/plotaxis.h>
#include <widget/plotobject.h>
#include <widget/plotview.h>

#include "R.h"

using namespace cdroid_demo_xiaoy;
HomeWindow::HomeWindow() : Window(0, 0, -1, -1) {
    ViewGroup *mainLayout = (ViewGroup *)LayoutInflater::from(getContext())->inflate("@layout/wind_main", this);

    PlotView * spPlotView = (PlotView *)mainLayout->findViewById(R::id::plotview_spending);

    spPlotView->setPadding(20,20,20,20);
    spPlotView->setShowGrid(true);

    spPlotView->invalidate();

    // spPlotView->resetPlot();
    PlotObject* po1;
    PlotObject* po2;
    

    // 辅助线
    spPlotView->axis(PlotView::LeftAxis)->setTickmarkVisible(true);
    spPlotView->axis(PlotView::RightAxis)->setTickmarkVisible(true);

    spPlotView->axis(PlotView::TopAxis)->setTickmarkVisible(false);
    spPlotView->axis(PlotView::BottomAxis)->setTickmarkVisible(false);

    // 坐标轴
    spPlotView->axis(PlotView::LeftAxis)->setVisible(true);
    spPlotView->axis(PlotView::BottomAxis)->setVisible(true);

    spPlotView->axis(PlotView::TopAxis)->setVisible(false);
    spPlotView->axis(PlotView::RightAxis)->setVisible(false);
    
    // 坐标轴 信息
    spPlotView->axis(PlotView::LeftAxis)->setTickLabelsShown(true);

    spPlotView->axis(PlotView::BottomAxis)->setTickLabelsShown(true);
    spPlotView->axis(PlotView::TopAxis)->setTickLabelsShown(false);
    spPlotView->axis(PlotView::RightAxis)->setTickLabelsShown(false);

    // 设置坐标轴 信息的数据模式
    // spPlotView->axis(PlotView::LeftAxis)->setTickLabelFormat('g',10,10);
    
    // 设置坐标轴 信息的数据范围
    spPlotView->setLimits(-0.5, 8.5, -0.1, 4.1);
    // length 设置为 0，相当于隐藏坐标轴标记
    spPlotView->axis(PlotView::BottomAxis)->setTickMarks(0,0);

    // 设置数据点，包括属性
    po1 = new PlotObject(Color::BLUE, PlotObject::Bars, 10, PlotObject::Pentagon);

    // po1->setShowLines(true); // 显示为 线状
    po1->setShowBars(true);  // 显示为 柱状

    Cairo::RefPtr<Cairo::LinearGradient> patternColor = Cairo::LinearGradient::create(0,320,0,0);
    patternColor->add_color_stop_rgb(0,0.310,0.035,0.553);
    patternColor->add_color_stop_rgb(1,0.694,0.318,0.565);
    
    Color clr(0xff9ab3e8);
    RefPtr<Pattern> labelColor = Cairo::SolidPattern::create_rgba(clr.red(),clr.green(),clr.blue(),clr.alpha());
    // 柱状图 生效的属性
    po1->setLabelPen(labelColor);   // 设置 柱状 label文本的颜色
    po1->setBarBrush(patternColor); // 设置 柱状 的内部颜色
    po1->setBarPen(patternColor);   // 设置 柱状 的边框颜色

    //线条 生效的属性
    po1->setLinePen(patternColor); // 设置 线状 颜色

    // 未知生效的属性
    // po1->setBrush(patternColor);
    // po1->setPen(patternColor);

    // 数据点
    po1->addPoint(0, 0.5," A ",0.5);
    po1->addPoint(1, 0.5," B ",0.5);
    po1->addPoint(2, 1.0," C ",0.5);
    po1->addPoint(3, 1.25," D ",0.5);
    po1->addPoint(4, 1.5,"",0.5);
    po1->addPoint(5, 2.5,"",0.5);
    po1->addPoint(6, 3.0,"",0.5);
    po1->addPoint(7, 1.5,"",0.5);
    po1->addPoint(8, 1.75,"",0.5);

    spPlotView->addPlotObject(po1);

    spPlotView->invalidate();
}

HomeWindow::~HomeWindow() {
}
